import http from './http' // 导入已配置的 axios 实例

// GET请求：获取用户列表
export async function getUsers<T>(): Promise<T> {
  try {
    return await http.get<T>('/api/users')
  } catch (error) {
    throw error
  }
}

// GET请求：获取用户详情
export async function getUserDetails<T>(userId: string): Promise<T> {
  try {
    return await http.get<T>(`/api/users/${userId}`)
  } catch (error) {
    throw error
  }
}

// POST请求：创建用户
export async function createUser<T>(data: Record<string, any>): Promise<T> {
  try {
    return await http.post<T>('/api/users', data)
  } catch (error) {
    throw error
  }
}

// PUT请求：编辑用户
export async function editUser<T>(
  userId: string,
  data: Record<string, any>
): Promise<T> {
  try {
    return await http.put<T>(`/api/users/${userId}`, data)
  } catch (error) {
    throw error
  }
}

// DELETE请求：删除用户
export async function deleteUser<T>(userId: string): Promise<T> {
  try {
    return await http.remove<T>(`/api/users/${userId}`)
  } catch (error) {
    throw error
  }
}

// 其他用户相关请求可以继续在此文件中添加
// 注册用户
export async function registerUser<T>(data: Record<string, any>): Promise<T> {
  try {
    return await http.post<T>('/api/users/register', data)
  } catch (error) {
    throw error
  }
}
// 登录用户
export async function loginUser<T>(data: Record<string, any>): Promise<T> {
  try {
    return await http.post<T>('/api/users/login', data)
  } catch (error) {
    throw error
  }
}

// 获取用户信息
export async function getUserInfo<T>(): Promise<T> {
  try {
    return await http.get<T>(`/api/users/me`)
  } catch (error) {
    throw error
  }
}
